//
//  Entry.m
//  TuiTe
//
//  Created by 张 霄鹤 on 10-4-23.
//  Copyright 2010 xhzhang. All rights reserved.
//

#import "Entry.h"


@implementation Entry

@synthesize eid;
@synthesize title;
@synthesize content;
@synthesize profileImage;
@synthesize authName;
@synthesize authURI;

- (void)parse:(Element *)el{
	if(el){
		Node *nd;
		
		nd = [el getChildByName:@"id"];
		if(nd){
			self.eid = [[nd getChildByName:@"#TEXT"] getValue];
		}
		
		nd = [el getChildByName:@"title"];
		if(nd){
			Element *exx = (Element *)nd;
			NSArray *es = [exx getElementsByName:@"#TEXT"];
			if(es){
				NSMutableString *str = [[NSMutableString alloc] init];
				for(Node *dn in es){
					[str appendString:[dn getValue]];
				}
				self.title = str;
				[str release];
			}
		}
		
		nd = [el getChildByName:@"content"];
		if(nd){
			Element *exx = (Element *)nd;
			NSArray *es = [exx getElementsByName:@"#TEXT"];
			if(es){
				NSMutableString *str = [[NSMutableString alloc] init];
				for(Node *dn in es){
					[str appendString:[dn getValue]];
				}
				self.content = str;
				[str release];
			}
		}
		
		NSArray *arr = [el getElementsByName:@"link"];
		if(arr){
			NSString *av;
			for (Element *ea in arr) {
				av = [ea getAttribute:@"rel"];
				if([av isEqualToString:@"image"]){
					self.profileImage = [ea getAttribute:@"href"];
					break;
				}
			}
		}
		
		nd = [el getChildByName:@"author"];
		if(nd){
			Element *author = (Element *)nd;
			nd = [author getChildByName:@"name"];
			if(nd){
				Element *exx = (Element *)nd;
				NSArray *es = [exx getElementsByName:@"#TEXT"];
				if(es){
					NSMutableString *str = [[NSMutableString alloc] init];
					for(Node *dn in es){
						[str appendString:[dn getValue]];
					}
					self.authName = str;
					[str release];
				}
			}
			
			nd = [author getChildByName:@"uri"];
			if(nd){
				self.authURI = [[nd getChildByName:@"#TEXT"] getValue];
			}			
		}		
	}
}

- (void)dealloc{
	[eid release];
	[title release];
	[content release];
	[profileImage release];
	[authName release];
	[authURI release];
	[super dealloc];
}

@end
